<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="{
      ...params,
      ...customParams,
    }"
    :keywords.sync="keywords"
    :getList="api"
    @getDetail="getDetail"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
				<view class="option">
          <view class="lf">档案编号</view>
          <view class="rl">{{ item.billNo }}</view>
        </view>
        <view class="option">
          <view class="lf">项目名称</view>
          <view class="rl">{{ item.projectName }}</view>
        </view>
				<view class="option">
				  <view class="lf">经营团队</view>
				  <view class="rl">{{ item.signteamName }}</view>
				</view>
				<view class="option">
				  <view class="lf">项目承接人</view>
				  <view class="rl">{{ item.undertakerName }}</view>
				</view>
				<view class="option">
				  <view class="lf">业主单位</view>
				  <view class="rl">{{ item.enterpriseName }}</view>
				</view>
				<view class="option">
				  <view class="lf">收款合同名称</view>
				  <view class="rl">{{ item.contractName }}</view>
				</view>
				
        <view class="option">
          <view class="lf">业务分类</view>
          <view class="rl">{{ item.categoryName }}</view>
        </view>
				<view class="option">
          <view class="lf">合同分配额(元)</view>
          <view class="rl">{{ item.contractAmount }}</view>
        </view>
        <view class="option">
          <view class="lf">生产团队</view>
          <view class="rl">{{ item.productTeam_dictText }}</view>
        </view>
				<view class="option">
				  <view class="lf">实施部门</view>
				  <view class="rl">{{ item.executeDepart_dictText }}</view>
				</view>
				<view class="option">
				  <view class="lf">部门负责人</view>
				  <view class="rl">{{ item.deptLeadName }}</view>
				</view>
				<view class="option">
				  <view class="lf">项目负责人</view>
				  <view class="rl">{{ item.projLeadName }}</view>
				</view>
				<view class="option">
				  <view class="lf">任务进度(%)</view>
				  <view class="rl">{{ item.taskProgress }}</view>
				</view>
				<view class="option">
				  <view class="lf">状态</view>
				  <view class="rl">{{ item.distributionType_dictText }}</view>
				</view>
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { relationTaskList, relationTaskInfo, queryPageListForProjectArchiveInputId } from '@/api/index.js'

export default {
  name: 'HSelectProjectInputPopup',
  data() {
    return {
      params: {
        column: 'createTime',
        order: 'desc',
        pageNo: 1,
        projectId: '',
        pageSize: 10,
      },
      keywords: '',
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    projectId: {
      type: String,
      default: '',
    },
    label: {
      type: String,
      default: 'categoryName',
    },
    customParams: {
      type: Object,
      default: () => {
        return {}
      },
    },
    api: {
      type: Function,
      default: queryPageListForProjectArchiveInputId,
    },
  },
  watch: {
    projectId: {
      handler(val) {
        this.params.projectId = val || ''
      },
      immediate: true,
    },
    keywords: {
      handler(val) {
        if (val) {
          this.params.categoryName = '*' + val + '*'
        } else {
          this.params.categoryName = '**'
        }
      },
      immediate: true,
    },
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      },
    },
  },
  methods: {
    // 获取详情
    getDetail(value) {
      queryPageListForProjectArchiveInputId({ id: value }).then((res) => {
        if (res.success) {
					if (res.result.records && res.result.records.length) {
						if (res.result.records.length == 1) {
							this.$set(this.$refs.hSelectInputPopup, 'title', res.result.records[0][this.label])
						}
					}
          this.$emit('change', {
            data: res.result[0],
            id: value,
          })
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped></style>
